package com.example.administrator.yunniuusedcar.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.common.base.BaseActivity;
import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.HomeAdapter;
import com.example.administrator.yunniuusedcar.adapter.ShopAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.HomeRanCarListBean;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.ShopImage_GridBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

// 商品详情 头部  图册
public class ShopInfoImagerActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_ESHcar1)
    TextView tvESHcar;
    @BindView(R.id.tv_title1)
    TextView tvTitle1;
    @BindView(R.id.tv_NumberImg)
    TextView tvNumberImg;
    @BindView(R.id.tv_MoseImg)
    TextView tvMoseImg;
    @BindView(R.id.iv_CarImager1)
    ImageView ivCarImager1;
    private RecyclerView recyclerView11;
    private ShopAdapter homeAdapter;
    private ArrayList listDatas;
    private int trm;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_recycleview;      //activity_shop_info_imager
    }

    @Override
    public void initView() {
        ButterKnife.bind(this);

        Intent intent = this.getIntent();

        //
        trm = intent.getIntExtra("RanCarid",0);
   //     initFindView();
 //       initFindByID();
        initRecycleView();

        // 请求网络
        initUloadSlideVP();
//        initUloadMenuList();
//        initUloadCarList();
    }

    private void initRecycleView() {
        recyclerView11 = findView(R.id.recycler_view1);

        recyclerView11.setLayoutManager(new LinearLayoutManager(this));

        //创建数据
        listDatas = new ArrayList();

        // 设置适配器显示列表
        homeAdapter = new ShopAdapter(this, listDatas);
        recyclerView11.setAdapter(homeAdapter);

    }
    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }


    @OnClick({R.id.iv_back, R.id.tv_NumberImg, R.id.tv_MoseImg, R.id.iv_CarImager1})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_NumberImg:  // 图片总张数
                break;
            case R.id.tv_MoseImg:    // 查看更多
                break;
            case R.id.iv_CarImager1:  // 单张汽车图片
                break;
        }
    }

    private void initUloadSlideVP() {

        String ull = IHttpService.HOST_URL + "Car/getCarimg";    // 汽车图册
        OkHttpUtils.post().url(ull).addParams("sign",IHttpService.SignVal).addParams("car_id", String.valueOf(trm)).build().execute(new StringCallback() {


            @Override
            public void onError(Call call, Exception e, int id) {
                System.out.println("-----====----------B"+ e);
                //          Global.showToast("请求超时！"+ e.getMessage());

            }

            @Override
            public void onResponse(String response, int id) {
                System.out.println("-----====-----------B1"+response);
                Gson jd = new Gson();

                          Global.showToast("======----=--==" + response);
                ShopImage_GridBean homeCarListBean = jd.fromJson(response, ShopImage_GridBean.class);
                //    int car_id = homeCarListBean.Car_id();
                listDatas.add(homeCarListBean);
//                homeAdapter.setDatas(listDatas);
                homeAdapter.notifyDataSetChanged();  //刷新


            }
        });
    }
}

